import { configureStore } from "@reduxjs/toolkit"
import userReducer from "./userReducer"
import undoable, { excludeAction, StateWithHistory } from 'redux-undo'
import componentsReducer from "./componentsReducer"
import type { UserStateType } from "./userReducer"
import type { ComponentsStateType } from "./componentsReducer"
import pageInfoReducer, { PageInfoType } from "./pageInfoReducer"


// 状态类型
export type StateType = {
  user: UserStateType
  // components: ComponentsStateType,
  components: StateWithHistory<ComponentsStateType> // 增加了 undo
  pageInfo: PageInfoType
}

const store = configureStore({
  reducer: {
    user: userReducer.reducer,
    // components: componentsReducer.reducer,// 没有 undo
    // 增加了 undo
    components: undoable(componentsReducer.reducer, {
      limit: 20, // 限制 undo 20 步
      filter: excludeAction([
        'components/resetComponents',
        'components/changeSelectedId',
        'components/selectPrevComponent',
        'components/selectNextComponent',
      ]),
    }),
    pageInfo: pageInfoReducer.reducer
  }
})

export default store
